/*
 * Copyright 2010 Chad Retz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jdocng.cmd.check;

import org.jdocng.shared.JavadocNgRuntimeException;
import org.junit.Assert;

import com.sun.javadoc.Doc;

/**
 * Asserts whether two {@link Doc}s are equal
 *
 * @author Chad Retz
 */
public abstract class DocAsserter<T extends Doc> extends EqualityAsserter<T> {

    @Override
    public void assertEqual(T expected, T actual) {
        //simple stuff
        Assert.assertEquals("commentText different on " + actual,
                expected.commentText(), actual.commentText());
        Assert.assertEquals("rawCommentText different on " + actual,
                expected.getRawCommentText(), actual.getRawCommentText());
        Assert.assertEquals("annotationType different on " + actual,
                expected.isAnnotationType(), actual.isAnnotationType());
        Assert.assertEquals("annotationTypeElement different on " + actual,
                expected.isAnnotationTypeElement(), actual.isAnnotationTypeElement());
        Assert.assertEquals("class different on " + actual,
                expected.isClass(), actual.isClass());
        Assert.assertEquals("constructor different on " + actual,
                expected.isConstructor(), actual.isConstructor());
        Assert.assertEquals("enum different on " + actual,
                expected.isEnum(), actual.isEnum());
        Assert.assertEquals("enumConstant different on " + actual,
                expected.isEnumConstant(), actual.isEnumConstant());
        Assert.assertEquals("error different on " + actual,
                expected.isError(), actual.isError());
        Assert.assertEquals("exception different on " + actual,
                expected.isException(), actual.isException());
        Assert.assertEquals("field different on " + actual,
                expected.isField(), actual.isField());
        Assert.assertEquals("included different on " + actual,
                expected.isIncluded(), actual.isIncluded());
        Assert.assertEquals("interface different on " + actual,
                expected.isInterface(), actual.isInterface());
        Assert.assertEquals("method different on " + actual,
                expected.isMethod(), actual.isMethod());
        Assert.assertEquals("ordinaryClass different on " + actual,
                expected.isOrdinaryClass(), actual.isOrdinaryClass());
        Assert.assertEquals("name different on " + actual,
                expected.name(), actual.name());
        //deeper...
        try {
            TagAsserter.getInstance().assertEqual("firstSentenceTags", 
                    expected.firstSentenceTags(), actual.firstSentenceTags());
            TagAsserter.getInstance().assertEqual("inlineTags", 
                    expected.inlineTags(), actual.inlineTags());
            SourcePositionAsserter.getInstance().assertEqual(
                    expected.position(), actual.position());
            SeeTagAsserter.getSeeTagInstance().assertEqual("seeTags", 
                    expected.seeTags(), actual.seeTags());
            TagAsserter.getInstance().assertEqual("tags", 
                    expected.tags(), actual.tags());
        } catch (AssertionError e) {
            throw new JavadocNgRuntimeException(
                    "Something different on " + actual, e);
        }
    }

}
